package com.springdemo.shape;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.MessageSource;

import com.springdemo.controller.DrawEvent;

import javax.annotation.*;

// @Component,@Service,@Repository,@Controller Annotation for making class a bean

public class Circle implements Shape,ApplicationEventPublisherAware {

	private Point center;
	private Point circum;
	@Autowired
	private MessageSource messageSource;
	
	private ApplicationEventPublisher eventPublisher;
	
	public void draw() {
		System.out.println("Drawing Circle at center:" + center + "with circum"
				+ circum);
		
		System.out.println(messageSource.getMessage("drawing.point", new Object[]{center.getX(),center.getY()},"Default Message",null));
		System.out.println("In circle:"+ messageSource.getMessage("greeting", null,"Default Message",null));
		eventPublisher.publishEvent(new DrawEvent(this));
		//throw new RuntimeException();
	}

	public Point getCenter() {
		return center;
	}

	// Annotation for making field center compulsory, otherwise exception is
	// thrown
	@Required
	public void setCenter(Point center) {
		this.center = center;
	}

	public Point getCircum() {
		return circum;
	}

	/*@Autowired
	@Qualifier("circleRelated")*/
	// @Resource Another way of decalring autowiring 
	public void setCircum(Point circum) {
		this.circum = circum;
	}
	
	@PostConstruct //Another way of decalring init method
	public void initCircle(){
		System.out.println("Inside initCircle");
	}
	
	@PreDestroy //Another way of decalring destroy method
	public void destroyCircle(){
		System.out.println("Inside destroyCircle");
	}

	public MessageSource getMessageSource() {
		return messageSource;
	}

	public void setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
	}

	public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) {
		// TODO Auto-generated method stub
		this.eventPublisher = eventPublisher;
	}
	
	
}
